#ifndef AI_REPLAY_H
#define AI_REPLAY_H



#include "ai.h"



/** @brief The main algorithm class.
*
*   This is not a real algorithm. It is only used for purposes of replaying games. It takes all recorded commands via
*   algorithm::init( player *p, const string& s = "" ) function from parameter s.
*
*   \image html ai_replay.jpeg
*/
class replay: public algorithm
{

public:

	//! @brief Constructor only assignes the name
	replay()
	{
		name = "Replay";
	};

	//! @brief Constructor only assignes the name
	~replay()
	{
		while ( !all_commands.empty() )
		{
			delete all_commands.front();
			all_commands.pop();
		}
	};

	/** @brief	Registrating function (adds ai algorithm to map)
	*/
	static void register_me()
	{
		register_metpl< replay >();
	};

	/** @brief	Cloning function for init purposes
	*	@return	clone of the algorithm
	*/
	virtual algorithm* clone()
	{
		replay* cl = clonetpl< replay >();
		return cl;
	};

	/**	@brief Function for initialising of algorithm
	*	sets owner and connects algorithm to game core and loads commands
	*	@param p this player will be set as owner, constraint: p != 0
	*	@param s commands line formated: "Command 1 # Command 2 # ... "
	*	@return true if init successful, else false
	*/
	virtual bool init( player* p, const string& s );

	/** @brief Function called at the beginning of buy
	*	@param gs current game state
	*/
	virtual void get_buy_commands( const game_state* gs );
	/** @brief Function called at the beginning of every turn
	*	@param gs current game state
	*/
	virtual void get_commands( const game_state* gs );


private:

	/** @brief	Parses lines when loading commands from file
	*	@param	cl line to parse
	*	@return	true if parsing successful, else false
	*/
	bool parse_commands_line( const string& cl );

	//! list of commands for current turn
	queue< list< string >* > all_commands;

};



#endif